package org.whh.beans.factory.support;

import org.whh.beans.factory.BeanFactory;
import org.whh.beans.factory.config.BeanDefinition;
import org.whh.common.exception.BeansException;

public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements BeanFactory {
    @Override
    public Object getBean(String name) throws BeansException {
        Object singleton = getSingleton(name);
        if (singleton != null){
            return singleton;
        }
        BeanDefinition beanDefinition = getBeanDefinition(name);
        singleton = createBean(name,beanDefinition);
        return singleton;
    }

    protected abstract Object createBean(String name, BeanDefinition beanDefinition) throws BeansException;

    protected abstract BeanDefinition getBeanDefinition(String name);

}
